import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../utils/screenAdapter.dart';
import './card_item_num_view.dart';
import '../../../service/HttpsClient.dart';
import '../controllers/cart_controller.dart';

class CardItemView extends GetView<CartController> {
  final Map cartItem;
  const CardItemView(this.cartItem, {super.key});
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(ScreenAdapter.radius(20)),
        border: Border(bottom: BorderSide(color: Colors.black12, width: 1)),
      ),
      padding: EdgeInsets.fromLTRB(
        0,
        ScreenAdapter.height(30),
        ScreenAdapter.width(20),
        ScreenAdapter.height(36),
      ),
      child: Row(
        children: [
          Expanded(
            flex: 1,
            child: Row(
              children: [
                Checkbox(
                  side: BorderSide(width: 1, color: Colors.black12),
                  value: cartItem["checked"],
                  onChanged: (value) {
                    controller.checkedGoods(cartItem);
                    print("点击了复选框$value");
                  },
                ),
                SizedBox(
                  height: ScreenAdapter.height(340),
                  child: Image.network(
                    HttpsClient.getImgUrl(cartItem["pic"]),
                    fit: BoxFit.fitHeight,
                  ),
                ), // 图片
              ],
            ),
          ), // 左边图标加复选框
          SizedBox(
            width: ScreenAdapter.width(640),
            // decoration: BoxDecoration(color: Colors.red),
            // height: ScreenAdapter.height(360),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  cartItem["title"]?? "",
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
                ElevatedButton(
                  style: ButtonStyle(
                    backgroundColor: WidgetStateProperty.all(Colors.black12),
                    foregroundColor: WidgetStateProperty.all(
                      Colors.black,
                    ), // 按钮字体颜色
                    padding: WidgetStateProperty.all(
                      EdgeInsets.symmetric(horizontal: ScreenAdapter.width(14), vertical: 0),
                    ), // 按钮内边距
                  ),
                  onPressed: () {},
                  child: Text("${cartItem["selectedAttr"]}"),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text("¥${cartItem["price"]}", style: TextStyle(color: Colors.orange)),
                    CardItemNumView(cartItem),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
